<template>
  <div class="person-head">
    <div
      class="person-head-title"
      v-for="(item, index) in tabs"
      :key="index"
      :class="{
        active: activeIndex === index,
        inactive: activeIndex !== index,
      }"
      @click="handleTabClick(item, index)"
    >
      <div>{{ item.label }}</div>
      <span class="line"></span>
    </div>
    <div class="opations" v-if="isSelect">
      <el-select
        placeholder="Select"
        style="width: 100px"
        v-model="value"
        clearable
        @change="handleSelectChange"
      >
        <el-option
          v-for="(item, index) in options"
          :key="index"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
const emits = defineEmits(["tabClick"]);
const value = ref("GMAT");
const props = defineProps({
  tabs: {
    type: Array,
    default: () => [],
  },
  isSelect: {
    type: Boolean,
    default: false,
  },
});

const activeIndex = ref(0); // 默认选中第一个 tab
const options = ref([
  {
    label: "GMAT",
    value: 1
  },
  {
    label: "GRE",
    value: 2
  },
  {
    label: "EA",
    value: 3
  },
]);
onMounted(() => {
  if (props.tabs?.length) {
    emits("tabClick", { item: props.tabs[0], index: 0 });
    emits("selectClick", 1);
  }
});

// 切换 tab
const handleTabClick = (item, index) => {
  activeIndex.value = index;
  emits("tabClick", { item, index });
};

const handleSelectChange = (value) => {
  console.log(value, 'value')
  emits("selectClick", value);
}
</script>

<style lang="scss" scoped>
.person-head {
  width: 100%;
  height: 50px;
  border-bottom: 1px solid var(--borderBottomColor);
  display: flex; // 横向排列
  align-items: center;
  position: relative;

  &-title {
    width: 80px;
    text-align: center;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: black; // 默认颜色为黑色
    font-size: var(--default13px);
    font-weight: 500;
    cursor: pointer; // 鼠标悬停时显示手型

    .line {
      width: 20px;
      height: 2px;
      background-color: transparent; // 默认不显示红线
    }

    // 选中状态
    &.active {
      color: var(--main-color);
      font-size: var(--default13px);
      .line {
        background-color: var(--main-color); // 选中时显示红线
      }
    }

    &.inactive {
      font-size: var(--default13px);
      color: var(--otherFontColor);
      font-weight: 400;
    }
  }
  .opations {
    // margin-right: 10px;
    position: absolute;
    right: 10px;
  }
}
</style>
